Send, Post and Echo Events from an Event Listener
This documentation is for an older version of ZK. For the latest one, please click here.
In addition to receiving events, an application could communicate among event listeners by posting or sending events to them.
Post Events
By use of the postEvent
method in the Events class, the application could post an event to the end of the event queue. This method returns immediately after placing the event into the queue. The event will be processed later after all events preceding it have been processed.
Send Events
By use of the sendEvent
method in the Events class, the application could ask ZK to process the specified event immediately. This method won't return until all event listeners of the specified event has been processed. The event is processed at the same thread.
Echo Events
By use of the echoEvent
method in the Events class, the application could ask the client to echo back the event for processing later. This method returned immediately after queuing the response asking the client to echo back the event.
Notice that, unlike sendEvent
and postEvent
, the event won't be processed in the current execution. Rather, it is processed later after the client echoes back the event. In other words, the event is processed later after the client has updated its user interfaces. Thus, it is useful to prompt the user before starting a long operation.
For example, you can open a highlighted window and then invoke echoEvent
to do the long operation after the client shows the window (and echoes back the event).
For example, we can use the showbusy method to show the busy message such that the user knows the system is busy. So, the end user will see "Execute..." first and then, after two seconds, "Done." in the following example. If you use postEvent
, the end user will see "Execute..." and "Done" at the same time after two seconds.
<window id="w" title="Test echoEvent">
<attribute name="onLater">
Thread.sleep(2000);
Clients.showBusy(null, false);
new Label("Done.").setParent(w);
</attribute>
<button label="echo">
<attribute name="onClick">
Clients.showBusy("Execute...", true);
Events.echoEvent("onLater", w, null);
</attribute>
</button>
</window>